package com.frame.pageform;

import java.util.Map;
import javax.servlet.http.HttpSession;
import ognl.OgnlContext;

public class PageOgnlContext {

	private Map variableContext;

	public void setVariable(String name,Object value)
	{
		variableContext.put(name,value);
	}
	public Map createtext(){
		if(variableContext==null){
			variableContext = new OgnlContext()
			{
				public Object get(Object key)
				{
					Object obj = super.get(key);
					if(obj != null)
						return obj;

					String s = key.toString();
					//如果获取值为空，则读取request或session里的值
					RequestContext context = RequestContext.getContext();
					if(obj == null)
						obj = context.getRequest().getAttribute(s);

					if(obj == null)
						obj = context.getRequest().getParameter(s);
					if(obj == null)
					{
						HttpSession session = context.getRequest().getSession(false);
						if(session != null)
							obj = session.getAttribute(s);
					}
					return obj;
				}

			};
		}
		RequestContext context = RequestContext.getContext();
		variableContext.put("request",context.getRequest());
		variableContext.put("requestContext",context);
		HttpSession session = context.getRequest().getSession(false);
		if(session != null)
			variableContext.put("session",session);
		return variableContext;
	}
}
